<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:a="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich"
    template="layout/template.xhtml">

<ui:define name="body">

    <h:form id="relationship" styleClass="edit">

        <rich:panel>
            <f:facet name="header">#{relationshipHome.managed ? 'Edit' : 'Add'} Relationship</f:facet>


            <s:decorate id="idField" template="layout/edit.xhtml">
                <ui:define name="label">Id</ui:define>
                <h:inputText id="id"
                       required="true"
                       disabled="#{relationshipHome.managed}"
                          value="#{relationshipHome.instance.id}">
                    <a:support event="onblur" reRender="idField" bypassUpdates="true" ajaxSingle="true"/>
                </h:inputText>
            </s:decorate>


            <s:decorate id="relationNameField" template="layout/edit.xhtml">
                <ui:define name="label">Relation name</ui:define>
                <h:inputText id="relationName"
                       required="true"
                           size="50"
                      maxlength="50"
                          value="#{relationshipHome.instance.relationName}">
                    <a:support event="onblur" reRender="relationNameField" bypassUpdates="true" ajaxSingle="true"/>
                </h:inputText>
            </s:decorate>


            <s:decorate id="relationDescField" template="layout/edit.xhtml">
                <ui:define name="label">Relation desc</ui:define>
                <h:inputTextarea id="relationDesc"
                               cols="80"
                               rows="10"
                              value="#{relationshipHome.instance.relationDesc}"/>
            </s:decorate>


            <div style="clear:both">
                <span class="required">*</span>
                required fields
            </div>

        </rich:panel>

        <div class="actionButtons">

            <h:commandButton id="save"
                          value="Save"
                         action="#{relationshipHome.persist}"
                       disabled="#{!relationshipHome.wired}"
                       rendered="#{!relationshipHome.managed}"/>

            <h:commandButton id="update"
                          value="Save"
                         action="#{relationshipHome.update}"
                       rendered="#{relationshipHome.managed}"/>

            <h:commandButton id="delete"
                          value="Delete"
                         action="#{relationshipHome.remove}"
                      immediate="true"
                       rendered="#{relationshipHome.managed}"/>

            <s:button id="cancelEdit"
                   value="Cancel"
             propagation="end"
                    view="/Relationship.xhtml"
                rendered="#{relationshipHome.managed}"/>

            <s:button id="cancelAdd"
                   value="Cancel"
             propagation="end"
                    view="/#{empty relationshipFrom ? 'RelationshipList' : relationshipFrom}.xhtml"
                rendered="#{!relationshipHome.managed}"/>

        </div>
    </h:form>

<rich:tabPanel switchType="ajax">

    <rich:tab label="Parents">
        <h:form styleClass="association" id="parentsChildren">

            <h:outputText value="There are no parents associated with this relationship."
                       rendered="#{empty relationshipHome.parents}"/>

            <rich:dataTable value="#{relationshipHome.parents}"
                           var="_parent"
                      rendered="#{not empty relationshipHome.parents}"
                    rowClasses="rvgRowOne,rvgRowTwo"
                            id="parentsTable">
                <rich:column sortBy="#{_parent.id}">
                    <f:facet name="header">Id</f:facet>
                    <h:outputText value="#{_parent.id}"/>
                </rich:column>
                <rich:column sortBy="#{_parent.firstName}">
                    <f:facet name="header">First name</f:facet>
                    <h:outputText value="#{_parent.firstName}"/>
                </rich:column>
                <rich:column sortBy="#{_parent.lastName}">
                    <f:facet name="header">Last name</f:facet>
                    <h:outputText value="#{_parent.lastName}"/>
                </rich:column>
                <rich:column sortBy="#{_parent.mobileNumber}">
                    <f:facet name="header">Mobile number</f:facet>
                    <h:outputText value="#{_parent.mobileNumber}"/>
                </rich:column>
                <rich:column sortBy="#{_parent.officePhone}">
                    <f:facet name="header">Office phone</f:facet>
                    <h:outputText value="#{_parent.officePhone}"/>
                </rich:column>
                <rich:column sortBy="#{_parent.email}">
                    <f:facet name="header">Email</f:facet>
                    <h:outputText value="#{_parent.email}"/>
                </rich:column>
            </rich:dataTable>

        </h:form>

        <f:subview rendered="#{relationshipHome.managed}" id="parents">
        <div class="actionButtons">
            <s:button id="addparent"
                   value="Add parent"
                    view="/ParentEdit.xhtml"
             propagation="none">
                 <f:param name="relationshipId"
                         value="#{relationshipHome.instance.id}"/>
                 <f:param name="parentFrom" value="Relationship"/>
            </s:button>
        </div>
        </f:subview>
    </rich:tab>
</rich:tabPanel>
</ui:define>

</ui:composition>
